package cn.zzmx.controller;


import cn.zzmx.entity.Product;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("file")
public class FileController {

    @Value("${pic.upload-path}")
    private String uploadPath;

    @Value("${pic.uploadResourcesHandler}")
    private String uploadResourcesHandler;


    @RequestMapping("/addFile")
    @ResponseBody
    public String uploadFile(@RequestParam Map<String, Product> map,
            @RequestParam("file") MultipartFile multipartFile) throws IOException {

        //获取上传文件名称
        String oldName = multipartFile.getOriginalFilename();
        UUID uuid = UUID.randomUUID();
        String newName = uuid + oldName.substring(oldName.lastIndexOf("."));

        File file = new File(uploadPath + newName);
        //组件写入
        multipartFile.transferTo(file);

        return "success!!!";
    }





}
